Ext.define('Xyh.controller.Role', {
	extend : 'Ext.app.Controller',

	views : [ 'role.Add', 'role.Edit', 'role.MenuConfig' ],

	init : function() {
		this.control( {
			'role button[action=addrole]' : {
				click : this.showAddRoleWindow
			},
//			'role' : {
//				itemdblclick : this.showUpdateRoleWindow
//			},
			'roleadd button[action=save]' : {
				click : this.addRole
			},
			'roleedit button[action=save]' : {
				click : this.updateRole
			},
			'menuconfig button[action=save]' : {
				click : this.menuConfig
			}
		});

	},

	showAddRoleWindow : function(button) {
		Ext.createWidget('roleadd');
	},
	showUpdateRoleWindow : function(grid, record) {
		var edit = Ext.createWidget('roleedit');
		edit.down('form').loadRecord(record);

	},
	addRole : function(button) {
		var win = button.up('window');
		var form = win.down('form').getForm();
		if (form.isValid()) {
			form.submit( {
				success : function(form, action) {
					Ext.Msg.alert('OK', '添加成功');
					win.close();
					Ext.getStore('Role').load();

				},
				failure : function(form, action) {
					Ext.Msg.alert('ERROR', '添加失败');
				}
			});
		}

	},
	updateRole : function(button) {
		var win = button.up('window');
		var form = win.down('form').getForm();
		if (form.isValid()) {
			form.submit( {
				success : function(form, action) {
					Ext.Msg.alert('OK', '修改成功成功');
					win.down('form').getRecord().set(
							win.down('form').getValues());
					win.close();

				},
				failure : function(form, action) {
					Ext.Msg.alert('ERROR', '修改失败');
				}
			});
		}
	},
	menuConfig : function(button) {
		var win = button.up('window');
		var form = win.down('form').getForm();
		if (form.isValid()) {
			form.submit( {
				success : function(form, action) {
					Ext.Msg.alert('OK', '修改成功成功');
					win.close();

				},
				failure : function(form, action) {
					Ext.Msg.alert('ERROR', '修改失败');
				}
			});
		}
	}

});